<?php

/**
 * This is the model class for table "vote_user_details".
 *
 * The followings are the available columns in table 'vote_user_details':
 * @property integer $id
 * @property string $name
 * @property string $email
 * @property integer $postcode
 * @property string $state
 * @property integer $receive_agt_updates
 * @property integer $receive_apples_updates
 * @property string $voted_for
 */
class VoteUserDetails extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return VoteUserDetails the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'vote_user_details';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('postcode, receive_agt_updates, receive_apples_updates', 'numerical', 'integerOnly'=>true),
			array('name, email, state', 'length', 'max'=>255),
			array('voted_for,phone_number,birth_year,birth_month', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name, email, postcode, state, receive_agt_updates, receive_apples_updates, voted_for', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'name' => 'Name',
			'email' => 'Email',
			'postcode' => 'Postcode',
			'state' => 'State',
			'receive_agt_updates' => 'Receive Agt Updates',
			'receive_apples_updates' => 'Receive Apples Updates',
			'voted_for' => 'Voted For',
                        'phone_number' => 'Day time phone number',
                        'birth_year' => 'Month and Year of birth',
                        'birth_month' => 'Month and Year of birth'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('postcode',$this->postcode);
		$criteria->compare('state',$this->state,true);
		$criteria->compare('receive_agt_updates',$this->receive_agt_updates);
		$criteria->compare('receive_apples_updates',$this->receive_apples_updates);
		$criteria->compare('voted_for',$this->voted_for,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}